package zdx.lesson;

import org.thymeleaf.util.EscapedAttributeUtils;

public class TestOOPVS
{
    public static void main(String[] args) {
        Student[]  grade = new Student[]{
                new Student("zs",188),
                new Student("ls",176),
                new Student("ww",192),
                new Student("zl",165)
        };

        printPArray(grade);
        pBubbleSort(grade);
        System.out.println();
        printPArray(grade);



    }



    public static void pBubbleSort(Student[] nums){
        for(int i=0;i<nums.length-1;i++)
        {
            for(int j=0;j<nums.length-i-1;j++)
            {
                Student s1=nums[j];
                Student s2=nums[j+1];//关于对象要有对象的完全引用指向的过程
                //交换过程中，需要有指向的交换与修改
//                if(nums[j].height>nums[j+1].height){
//                    swap(nums[j],nums[j+1]);
                if(s1.height>s2.height)
                {//我这里就出了bug
                    //虽然更改了两个对象的指向
                    //但是在对象数组里面，对象的位置没有进行交换。
                    Student temp = s1;
                    s1=s2;
                    s2=temp;
                }
            }
        }
    }

    public static void printPArray(Student[] nums)
    {
        for(Student student : nums)
        {
            System.out.println("姓名    "+student.name+"   身高: "+student.height+"   ");
        }
    }





}

class Student
{
    public String name;
    public int    height;

    public Student(String name, int height) {
        this.name = name;
        this.height = height;
    }
}
